from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-23 14:03:07.662450
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 23, Dec, 2022
Time: 14:03:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.2878
Nobs: 879.000 HQIC: -51.5900
Log likelihood: 11620.8 FPE: 3.26214e-23
AIC: -51.7771 Det(Omega_mle): 2.94636e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297030 0.049613 5.987 0.000
L1.Burgenland 0.105556 0.033962 3.108 0.002
L1.Kärnten -0.106897 0.018239 -5.861 0.000
L1.Niederösterreich 0.213497 0.071229 2.997 0.003
L1.Oberösterreich 0.086402 0.067446 1.281 0.200
L1.Salzburg 0.249683 0.036058 6.924 0.000
L1.Steiermark 0.030186 0.047358 0.637 0.524
L1.Tirol 0.127547 0.038533 3.310 0.001
L1.Vorarlberg -0.062188 0.033142 -1.876 0.061
L1.Wien 0.063452 0.060108 1.056 0.291
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063794 0.102000 0.625 0.532
L1.Burgenland -0.009893 0.069823 -0.142 0.887
L1.Kärnten 0.049279 0.037496 1.314 0.189
L1.Niederösterreich -0.173205 0.146439 -1.183 0.237
L1.Oberösterreich 0.362233 0.138662 2.612 0.009
L1.Salzburg 0.286068 0.074132 3.859 0.000
L1.Steiermark 0.108688 0.097362 1.116 0.264
L1.Tirol 0.319097 0.079219 4.028 0.000
L1.Vorarlberg 0.024669 0.068136 0.362 0.717
L1.Wien -0.024805 0.123575 -0.201 0.841
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199851 0.025717 7.771 0.000
L1.Burgenland 0.090082 0.017604 5.117 0.000
L1.Kärnten -0.009205 0.009454 -0.974 0.330
L1.Niederösterreich 0.268006 0.036921 7.259 0.000
L1.Oberösterreich 0.113298 0.034960 3.241 0.001
L1.Salzburg 0.052908 0.018691 2.831 0.005
L1.Steiermark 0.015438 0.024548 0.629 0.529
L1.Tirol 0.102924 0.019973 5.153 0.000
L1.Vorarlberg 0.056535 0.017179 3.291 0.001
L1.Wien 0.111146 0.031157 3.567 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104537 0.026402 3.959 0.000
L1.Burgenland 0.047555 0.018073 2.631 0.009
L1.Kärnten -0.017023 0.009706 -1.754 0.079
L1.Niederösterreich 0.197501 0.037905 5.210 0.000
L1.Oberösterreich 0.278365 0.035892 7.756 0.000
L1.Salzburg 0.117851 0.019188 6.142 0.000
L1.Steiermark 0.100099 0.025201 3.972 0.000
L1.Tirol 0.127245 0.020505 6.205 0.000
L1.Vorarlberg 0.069830 0.017636 3.959 0.000
L1.Wien -0.026807 0.031987 -0.838 0.402
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131766 0.047642 2.766 0.006
L1.Burgenland -0.053966 0.032613 -1.655 0.098
L1.Kärnten -0.037034 0.017514 -2.115 0.034
L1.Niederösterreich 0.166620 0.068399 2.436 0.015
L1.Oberösterreich 0.132985 0.064766 2.053 0.040
L1.Salzburg 0.290875 0.034625 8.401 0.000
L1.Steiermark 0.034387 0.045476 0.756 0.450
L1.Tirol 0.162000 0.037001 4.378 0.000
L1.Vorarlberg 0.107914 0.031825 3.391 0.001
L1.Wien 0.066030 0.057719 1.144 0.253
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060790 0.037754 1.610 0.107
L1.Burgenland 0.038478 0.025844 1.489 0.137
L1.Kärnten 0.049827 0.013879 3.590 0.000
L1.Niederösterreich 0.227773 0.054203 4.202 0.000
L1.Oberösterreich 0.269930 0.051324 5.259 0.000
L1.Salzburg 0.059133 0.027439 2.155 0.031
L1.Steiermark -0.007008 0.036037 -0.194 0.846
L1.Tirol 0.157937 0.029322 5.386 0.000
L1.Vorarlberg 0.068921 0.025220 2.733 0.006
L1.Wien 0.074876 0.045740 1.637 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185415 0.045301 4.093 0.000
L1.Burgenland 0.018174 0.031011 0.586 0.558
L1.Kärnten -0.060181 0.016653 -3.614 0.000
L1.Niederösterreich -0.094054 0.065038 -1.446 0.148
L1.Oberösterreich 0.175272 0.061584 2.846 0.004
L1.Salzburg 0.061045 0.032924 1.854 0.064
L1.Steiermark 0.230304 0.043242 5.326 0.000
L1.Tirol 0.488203 0.035184 13.876 0.000
L1.Vorarlberg 0.051285 0.030261 1.695 0.090
L1.Wien -0.053726 0.054884 -0.979 0.328
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158304 0.051395 3.080 0.002
L1.Burgenland 0.000141 0.035182 0.004 0.997
L1.Kärnten 0.066409 0.018893 3.515 0.000
L1.Niederösterreich 0.202181 0.073786 2.740 0.006
L1.Oberösterreich -0.069908 0.069867 -1.001 0.317
L1.Salzburg 0.220772 0.037353 5.910 0.000
L1.Steiermark 0.112347 0.049058 2.290 0.022
L1.Tirol 0.085170 0.039916 2.134 0.033
L1.Vorarlberg 0.123442 0.034331 3.596 0.000
L1.Wien 0.102799 0.062266 1.651 0.099
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359992 0.030427 11.831 0.000
L1.Burgenland 0.007052 0.020829 0.339 0.735
L1.Kärnten -0.025652 0.011185 -2.293 0.022
L1.Niederösterreich 0.228725 0.043684 5.236 0.000
L1.Oberösterreich 0.154035 0.041364 3.724 0.000
L1.Salzburg 0.052640 0.022114 2.380 0.017
L1.Steiermark -0.016632 0.029044 -0.573 0.567
L1.Tirol 0.122596 0.023631 5.188 0.000
L1.Vorarlberg 0.071027 0.020325 3.494 0.000
L1.Wien 0.047854 0.036863 1.298 0.194
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038602 0.160202 0.181167 0.169044 0.142525 0.127557 0.065823 0.218723
Kärnten 0.038602 1.000000 0.001488 0.132103 0.026941 0.099317 0.432455 -0.049299 0.100813
Niederösterreich 0.160202 0.001488 1.000000 0.346406 0.170662 0.313116 0.127934 0.192316 0.339321
Oberösterreich 0.181167 0.132103 0.346406 1.000000 0.234197 0.341701 0.178304 0.179985 0.271716
Salzburg 0.169044 0.026941 0.170662 0.234197 1.000000 0.153744 0.137047 0.153369 0.139644
Steiermark 0.142525 0.099317 0.313116 0.341701 0.153744 1.000000 0.159322 0.148584 0.094344
Tirol 0.127557 0.432455 0.127934 0.178304 0.137047 0.159322 1.000000 0.122765 0.162503
Vorarlberg 0.065823 -0.049299 0.192316 0.179985 0.153369 0.148584 0.122765 1.000000 0.018791
Wien 0.218723 0.100813 0.339321 0.271716 0.139644 0.094344 0.162503 0.018791 1.000000